﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DragAndDrop.aspx.cs" Inherits="Actuals.DragAndDrop" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        body
        {
            font: bold 12px arial;
        }
        
        span
        {
            float: left;
            margin-top: 17px;
            text-align: center;
            width: 100%;
        }
        
        #trash, #items, .item
        {
            height: 50px;
            width: 50px;
        }
        
        #trash
        {
            color: #354e62;
        }
        
        #items
        {
            margin-top: 10px;
            width: 100%;
        }
        
        .todoitem
        {
            background: #cdcdcd;
            color: #3b3b3b;
            float: left;
            margin-right: 10px;
        }
        
        .inprogitem
        {
            background:yellow;
            color: black;
            float: left;
            margin-right: 10px;
        }
        
        .closeditem
        {
            background: green;
            color: black;
            float: left;
            margin-right: 10px;
        }
        .over
        {
            background-color: yellow;
        }
        
        .out
        {
            background-color: #a6bcce;
        }
    </style>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.ui.core.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.ui.widget.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.ui.mouse.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.ui.draggable.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.ui.droppable.js") %>"></script>
    <script type="text/javascript">

        $(function () {
            $(".todoitem").draggable({
                containment: "#container",
                revert: false,
                start: function (event, ui) {
                    ui.helper.data('rejected', false);
                    // alert(ui.helper.data('type'));
                    if (!ui.helper.data('type')) {
                        // alert('undefined');
                        ui.helper.data('type', 'todo');
                    }
                    ui.helper.data('original-position', ui.helper.offset());
                },
                stop: function (event, ui) {
                    if (ui.helper.data('rejected') == true) {
                        ui.helper.offset(ui.helper.data('original-position'));
                    }
                }






            });


            $("#inprog").droppable({
                tolerance: 'touch',
                //accept: '#todoitem',
                drop: function (event, ui) {

                    if (ui.helper.data('type') == 'todo') {
                        var answer = confirm('Permantly move this item?');
                        // alert(answer);
                        if (answer == false) {
                            ui.draggable.data('rejected', true);
                        }
                        else {

                            // $(this).removeClass('todoitem').addClass('inprogitem');
                            ui.draggable.removeClass('todoitem').addClass('inprogitem');
                            ui.helper.data('type', 'inprog');
                            ui.draggable.data('rejected', false);


                        }
                    }
                    else {
                        alert('you cannot do this action');
                        ui.draggable.data('rejected', true);
                    }
                }
            });

            $("#done").droppable({
                tolerance: 'touch',
                //accept: '#inprogitem',
                drop: function (event, ui) {
                    if (ui.helper.data('type') == 'inprog') {
                        var answer = confirm('Permantly move this item?');

                        if (answer == false) {
                            ui.draggable.data('rejected', true);
                        }
                        else {
                            // $(this).removeClass('inprogitem').addClass('closeditem');
                            ui.draggable.removeClass('inprogitem').addClass('closeditem');
                            ui.helper.data('type', 'done');
                            ui.draggable.data('rejected', false);
                        }
                    }
                    else {
                        alert('you cannot do this action');
                        ui.draggable.data('rejected', true);
                    }
                }
            });

        });

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="container" style="width: 60%;">
        <table border="1" width="100%">
            <tr>
                <td height="100" width="30%">
                    <div id="todo" style="height:100%;width:100%">
                        <div class="todoitem">
                            <span>Item 1</span></div>
                        <div class="todoitem">
                            <span>Item 2</span></div>
                        <div class="todoitem">
                            <span>Item 3</span></div>
                    </div>
                </td>
                <td height="100" width="30%">
                    <div id="inprog"  style="height:100%;width:100%">
                    </div>
                </td>
                <td height="100" width="30%"  style="height:100%;width:100%">
                    <div id="done" style="height:100%;width:100%">
                    </div>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
